<#assign sql = 'select count(*) from app.entity e inner join app.entity_type et on(e.entity_type_id=et.entity_type_id) where et.code = \'TEMP\''>
<#assign size = sqlUtils.executeCount(sql)>
<#if (size<0)>
	ERROR: CAN'T EXECUTE SQL COMMAND:
	${sql} 
	DESCRIPTION:
	${sqlUtils.getLastError()}
	ERROR KEY:
	${sqlUtils.getLastKeyError()}
</#if>
<#assign sql = 'select e.* from app.entity e inner join app.entity_type et on(e.entity_type_id=et.entity_type_id) where et.code = \'TEMP\''>
<#assign resultset = sqlUtils.executeSelect(sql)>
<#if !(resultset??) >
	ERROR: CAN'T EXECUTE SQL COMMAND:
	${sql} 
	DESCRIPTION:
	${sqlUtils.getLastError()}
	ERROR KEY:
	${sqlUtils.getLastKeyError()}
<#else>
	<#list 1..size as c>
		<#if sqlUtils.moveNext(resultset)>
			<#assign sql = 'insert into app.entity_file(created_by, updated_by, content, entity_id) values(\'remas\', \'remas\', ?, ?)'>
			<#assign ps = sqlUtils.getPreparedStatement(sql)>
			<#if !(ps??) >
				ERROR: CAN'T EXECUTE SQL COMMAND:
				${sql} 
				DESCRIPTION:
				${sqlUtils.getLastError()}
				ERROR KEY:
				${sqlUtils.getLastKeyError()}
			<#else>
				<#assign stream = sqlUtils.setFileFromResource(ps, 1, resultset.getString("code"))>				
				${ps.setLong(2, resultset.getLong("entity_id"))}
				<#assign updated = ps.executeUpdate()>
			</#if>
		</#if>
	</#list>
</#if>